import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';
interface Message {
	filter: {
		dept: string
		project: string
		risk_type: string
		risk_status: string
		time112: number
		time212: number
		pn: number
	};
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}



export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {

	const query = complex_query(action_id, session_id, systemid);
	const dt = await query
		// 添加字段
		.add_field('risk_management', 'risk_no', 'risk_no')
		.add_field('risk_management', 'risk_type', 'risk_type')
		.add_field('risk_management', 'project_name', 'project_name')
		.add_field('risk_management', 'risk_content', 'risk_content')
		.add_field('risk_management', 'create_time', 'create_time')
		.add_field('risk_management', 'risk_status', 'risk_status')
		.add_field('risk_management', 'project_no', 'project_no')
		.add_field('company_project', 'project_no', 'project_no')
		.add_field('company_project', 'equip_depart_name', 'equip_depart_name')
		.add_field('company_project', 'equip_depart_no', 'equip_depart_no')
		.add_field('company_project', 'project_manager', 'project_manager')
		.inner_join('risk_management', 'company_project', ['project_no', 'project_no'])
		.where_like('company_project', 'equip_depart_name', '%' + message.filter.dept + '%')
		.where_like('risk_management', 'project_name', '%' + message.filter.project + '%')
		.where_like('risk_management', 'risk_type', '%' + message.filter.risk_type + '%')
		.where_like('risk_management', 'risk_status', '%' + message.filter.risk_status + '%')
		.where_gte('risk_management', 'create_time', message.filter.time112)
		.where_lte('risk_management', 'create_time', message.filter.time212)
		.exec();
	return dt;

}
